//
//  FFServicerListCell.m
//  LLWallet
//
//  Created by tt on 2020/9/15.
//

#import "FFServicerListCell.h"

@implementation FFServicerListModel

- (Class)cell {
    return FFServicerListCell.class;
}

- (NSNumber *)showArrow {
    return @(false);
}

@end

@interface FFServicerListCell ()

@property(nonatomic,strong) UILabel *nameLbl;

@property(nonatomic,strong) UIImageView *avatarImgView;

@property(nonatomic,strong) WKOfficialTag *officialTag;


@end

@implementation FFServicerListCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 80.0f);
}

- (void)setupUI {
    [super setupUI];
    [self addSubview:self.nameLbl];
    [self addSubview:self.avatarImgView];
    [self addSubview:self.officialTag];
}


- (void)refresh:(FFServicerListModel *)model {
    [super refresh:model];
    
    [self.avatarImgView setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[WKApp shared].config.defaultAvatar];
    self.nameLbl.text = model.name;
    
}

- (UILabel *)nameLbl {
    if(!_nameLbl) {
        _nameLbl = [[UILabel alloc] init];
        [_nameLbl setFont:[[WKApp shared].config appFontOfSizeMedium:16.0f]];
        [_nameLbl setTextColor:[WKApp shared].config.defaultTextColor];
    }
    return _nameLbl;
}

- (UIImageView *)avatarImgView {
    if(!_avatarImgView) {
        _avatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 45.0f, 45.0f)];
        _avatarImgView.layer.masksToBounds = YES;
        _avatarImgView.layer.cornerRadius = _avatarImgView.lim_height/2.0f;
    }
    return _avatarImgView;
}

- (WKOfficialTag *)officialTag {
    if(!_officialTag) {
        _officialTag = [WKOfficialTag new];
    }
    return _officialTag;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.avatarImgView.lim_left = 15.0f;
    self.avatarImgView.lim_top = self.lim_height/2.0f - self.avatarImgView.lim_height/2.0f;
    
    [self.nameLbl sizeToFit];
    self.nameLbl.lim_top = self.lim_height/2.0f - self.nameLbl.lim_height/2.0f;
    self.nameLbl.lim_left = self.avatarImgView.lim_right + 10.0f;
    if(self.nameLbl.lim_width>self.lim_width - self.nameLbl.lim_left * 2 - 20.0f) {
        self.nameLbl.lim_width = self.lim_width - self.avatarImgView.lim_right - 60.0f;
    }
    
    self.officialTag.lim_top = self.nameLbl.lim_top + (self.nameLbl.lim_height/2.0f - self.officialTag.lim_height/2.0f);
    self.officialTag.lim_left = self.nameLbl.lim_right + 4.0f;
    
}

@end
